package com.atguigu.delivery.servlet;

import com.atguigu.delivery.service.api.DeliveryService;
import com.atguigu.delivery.service.impl.DeliveryServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet(urlPatterns = "/DeliveryServlet/Remove")
public class DeliveryServletRemove extends HttpServlet {

    private DeliveryService deliveryService = new DeliveryServiceImpl();

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        // <a class="delAnchor" href="/DeliveryServletRemove?id=5">删除</a>
        // 1、获取请求参数，获取 id 值
        String id = request.getParameter("id");

        // 2、调用 Service 层方法，根据 id 执行删除
        deliveryService.removeDeliveryById(id);

        // 3、回到列表页面
        response.sendRedirect("/DeliveryServlet/List");
    }
}
